package com.bj.rd.Test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.bj.rd.entity.Student;

public class TestEcache {
public static void main(String[] args) {
	// 1.加载配置文件
			Configuration config = new Configuration().configure();
			// 2.创建session工厂
			SessionFactory sessionFactory = config.buildSessionFactory();
			// 3.获取session
			Session session = sessionFactory.openSession();
			// 4.开启事务
			Transaction transaction = session.beginTransaction();
			 Student stu = (Student) session.get(Student.class, "001");//从数据库获取  
			 System.out.println(stu.getName());
			 Student stu2 = (Student) session.get(Student.class, "001"); //从缓存中 
			 System.out.println(stu2.getName());
			 Student stu3 = (Student) session.get(Student.class,"001"); //从缓存中 
			 System.out.println(stu3.getName());   
			 transaction.commit();
			 session.close();
			 sessionFactory.close();
}
}
